package demo.set;

import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;

public class MySet {
	public static void main(String[] args) {
		
		HashSet<String> hashSet=new HashSet<String>(4,.75f);
		
		hashSet.add(new  String("hello"));
		hashSet.add(new String("world"));
		hashSet.add(new  String("q"));
		hashSet.add(new String("2"));
		System.out.println(hashSet.add("2"));
		/*hashSet.add(new MyObject(12));
		hashSet.add(new MyObject(12));
		hashSet.add(new MyObject(12));*/
		
		HashSet<Integer> hasSet=new HashSet<Integer>();
		hasSet.add(2);
		hasSet.add(4);
		System.out.println(hashSet);
       System.out.println(hashSet.size());		
		 System.out.println("Object removed :"+hashSet.remove("2"));

		System.out.println(hashSet);
	     System.out.println("checking"+hashSet.contains("q"));
	     //hashSet.addAll(hasSet);
	    
		System.out.println(hashSet.size()); 
		// To get value form hash Set one by One 
		
	Iterator<String> iterator=	  hashSet.iterator();
	   while (iterator.hasNext()) {
		String string = iterator.next();
		System.out.println(string);
		
	}
	   for (String s : hashSet) {
		System.out.println(s);
	}
	 hashSet.toArray();
	/* Enumeration enumeration=(Enumeration)   hashSet.iterator();
	 System.out.println("Iterating  using enumeration");
	   while (enumeration.hasMoreElements()) {
		String object = (String) enumeration.nextElement();
		 System.out.println(object);
	}*/
	   
	   
	}

}
